package com.ruoyi.youtian.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.youtian.domain.PointEquipment;
import com.ruoyi.youtian.service.IPointEquipmentService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据采集点位与设备关联Controller
 *
 * @author ruoyi
 * @date 2022-09-15
 */
@Controller
@RequestMapping("/youtian/point-equipment")
public class PointEquipmentController extends BaseController
{
    @Autowired
    private IPointEquipmentService pointEquipmentService;

    /**
     * 查询点位与设备关联列表
     */
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(PointEquipment pointEquipment)
    {
        startPage();
        List<PointEquipment> list = pointEquipmentService.selectPointEquipmentList(pointEquipment);
        return getDataTable(list);
    }

    /**
     * 导出点位与设备关联列表
     */
    @Log(title = "点位与设备关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public void export(HttpServletResponse response, PointEquipment pointEquipment)
    {
        List<PointEquipment> list = pointEquipmentService.selectPointEquipmentList(pointEquipment);
        ExcelUtil<PointEquipment> util = new ExcelUtil<PointEquipment>(PointEquipment.class);
        util.exportExcel(response, list, "点位与设备关联数据");
    }

    /**
     * 获取点位与设备关联详细信息
     */
    @GetMapping(value = "/{id}")
    @ResponseBody
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(pointEquipmentService.selectPointEquipmentById(id));
    }

    /**
     * 新增点位与设备关联
     *
     * 为点位绑定设备
     */
    @Log(title = "点位与设备关联", businessType = BusinessType.INSERT)
    @PostMapping
    @ResponseBody
    public AjaxResult add(@RequestBody PointEquipment pointEquipment)
    {
        return toAjax(pointEquipmentService.insertPointEquipment(pointEquipment));
    }

    /**
     * 修改点位与设备关联
     */
    @Log(title = "点位与设备关联", businessType = BusinessType.UPDATE)
    @PutMapping
    @ResponseBody
    public AjaxResult edit(@RequestBody PointEquipment pointEquipment)
    {
        return toAjax(pointEquipmentService.updatePointEquipment(pointEquipment));
    }

    /**
     * 删除点位与设备关联
     */
    @Log(title = "点位与设备关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ResponseBody
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pointEquipmentService.deletePointEquipmentByIds(ids));
    }
    /**
     * 删除点位与设备关联
     */
    @DeleteMapping("/delete")
    @ResponseBody
    public AjaxResult deletePointEquipment(PointEquipment pointEquipment)
    {
        return AjaxResult.success(pointEquipmentService.deletePointEquipment(pointEquipment));
    }

}
